from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout
from conan.tools.files import get
import os

class capicxxcoreruntimeRecipe(ConanFile):
    name = "commonapi"
    version = "3.2.3"
    license = "MPL-2.0"
    author = "Bayerische Motoren Werke Aktiengesellschaft (BMW AG)"
    url = "https://github.com/COVESA/capicxx-core-runtime"
    description = ("The CommonAPI C++ Core Runtime is part of the CommonAPI C++ project which provides a high-level C++ framework for inter-process communication. It supports the development of service-oriented applications in a vehicle's electronic control units (ECUs).")
    topics = ("CommonAPI", "C++", "service-oriented", "automotive", "inter-process-communication")
    # Binary configuration
    settings = "os", "compiler", "build_type", "arch"
    options = {"shared": [True, False], "fPIC": [True, False]}
    default_options = {"shared": False, "fPIC": True}
    #exports_sources = "lib_src/capicxx-core-runtime-3.2.3-r7/*"


    def source(self):
        # Please, be aware that using the head of the branch instead of an immutable tag
        # or commit is a bad practice and not allowed by Conan
        get(self, "https://github.com/COVESA/capicxx-core-runtime/archive/refs/tags/3.2.3-r7.zip",
                  strip_root=True)
        cmake_file_path = os.path.join(self.source_folder, "CMakeLists.txt")
        if os.path.exists(cmake_file_path):
            print("CMakeLists.txt exists: Yes")
            # 这里可以放置使用CMake构建的逻辑
        else:
            print("CMakeLists.txt exists: No")
            # 这里可以放置使用其他构建系统的逻辑
    def requirements(self):
        self.requires("boost/1.84.0")

    def config_options(self):
        if self.settings.os == "Windows":
            del self.options.fPIC

    def layout(self):
        cmake_layout(self)
#        self.folders.source = "lib_src/capicxx-core-runtime-3.2.3-r7"
        
    def generate(self):
        tc = CMakeToolchain(self)
        tc.generate()

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

    def package(self):
        cmake = CMake(self)
        cmake.install()

    def package_info(self):
        self.cpp_info.libs = ["CommonAPI"]